package Com.Hupochuan.Uil.Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Com.Hupochuan.Uil.Util.DoTool;

@SuppressWarnings("serial")
public class DoRunServlet extends HttpServlet{
	/*
	 * get方法
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.servletFilter(request, response);
	}

	/*
	 * post方法
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.servletFilter(request, response);
	}
	
	private DoTool doTool;
	
	/*
	 * servlet过滤器
	 */
	public void servletFilter(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
		
		this.doTool = new DoTool(request,response);
		
		//获得路径参数
		String path0 = this.doTool.getPathPara(0);
		String path1 = this.doTool.getPathPara(1);
		
		//如果访问的不是登陆页面
		if(path0.equals("admin") && !path1.equals("login") && !path1.equals("ajax") && !path1.equals("ajaxUpload")){
			//Session中没有管理员用户对象
			if(this.doTool.getSess("sessionAdmin") == null){
				//重定向回管理员登陆页
				this.doTool.redirect("/admin/login");
				return;
			}
		}
		
		this.doRun();
	}
	
	/*
	 * 运行
	 */
	public void doRun(){}

	public DoTool getDoTool() {
		return doTool;
	}
}
